home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / stngpasm / pure_c / include / sting / domain.sh < prev    next >
Encoding:
Text File  |  1997-08-09  |  9.0 KB  |  407 lines

  1. ;----------------------------------------------------------------------------
  2. ; File name:    DOMAIN.SH            Revision date:    1997.08.09
  3. ; Authors:    Ronald Andersson        Creation date:    1997.08.01
  4. ;                        Version:    1.00
  5. ;----------------------------------------------------------------------------
  6. ; Purpose:    Defines constants and macros which are useful in handling
  7. ;        domain names and IP addresses, including some conversions.
  8. ;----------------------------------------------------------------------------
  9. ;Required header declarations:
  10. ;
  11. ;    .include    "uran\STRUCT.SH"
  12. ;    .include    "sting\DOMAIN.SH"
  13. ;
  14. ;copy the above to the header of your program and 'uncomment' the includes
  15. ;
  16. ;----------------------------------------------------------------------------
  17. ;NB: Having used any of these macros, you have to include a call like this:
  18. ;
  19. ;        make    DOMAIN_links
  20. ;
  21. ;    This must be somewhere in the executable code, after all 'tcon_' macros
  22. ;    that are to be used in the program have been called at least once.
  23. ;----------------------------------------------------------------------------
  24. ;Available macros and their usage:
  25. ;
  26. ;-------------------------------------------------------------------------------------)
  27. ;
  28. .MACRO    DOMAIN_links
  29.     _unidef    is_domname
  30.     _unidef    is_dip
  31.     _unidef    is_unblank
  32.     _unidef    next_dip
  33.     _unidef    skip_space
  34.     _unidef    diptobip
  35.     _unidef    biptodip
  36.     _unidef    biptodrip
  37.     _unidef    pass_RRname
  38. .ENDM    DOMAIN_links
  39. ;
  40.     _unidec    is_domname
  41.     _unidec    is_dip
  42.     _unidec    is_unblank
  43.     _unidec    next_dip
  44.     _unidec    skip_space
  45.     _unidec    diptobip
  46.     _unidec    biptodip
  47.     _unidec    biptodrip
  48.     _unidec    pass_RRname
  49. ;
  50. ;-------------------------------------------------------------------------------------)
  51. ;char    *is_domname(char *string, len)    /* flags -> domain name */
  52. ;
  53. .MACRO    is_domname    string_p,len
  54.     PUREC_func    is_domname,2,7,string_p,len
  55. .ENDM    is_domname
  56. ;
  57. .MACRO    code_is_domname
  58.     movem.l    d1-d2/a1,-(sp)
  59.     move.l    a0,d1        ;NULL string ?
  60.     beq.s    .exit
  61.     move.l    a0,a1        ;a1 = a0 = string
  62.     move    d0,d2        ;d2 = len
  63.     ble.s    .label_bad
  64.     skip_space    (a0)    ;string passed to non-blank
  65.     move.l    a0,d0
  66.     sub.l    a1,d0        ;d0 = passed length
  67.     sub    d0,d2        ;reduce total length by passed blanks
  68.     ble.s    .label_bad
  69.     move.l    a0,a1        ;a1 = a0 = non_blank string
  70.     move    d2,d0        ;d0 = remaining len
  71. .label_start:
  72.     clr    d2        ;d2 = 0  indicates label starts
  73. .label_char:
  74.     dbra    d0,.test_char    ;test len characters
  75.     tst    d2        ;last label empty ?
  76.     beq.s    .label_bad
  77. .label_ok:
  78.     movem.l    (sp)+,d1-d2/a1
  79.     rts            ;return a0 -> domname
  80. ;
  81. .test_char:
  82.     move.b    (a1)+,d1    ;d1 = current char
  83.     beq.s    .label_bad
  84.     cmp.b    #'.',d1
  85.     beq.s    .label_start
  86.     tst    d2
  87.     beq.s    .test_alfa
  88.     cmp.b    #'-',d1
  89.     beq.s    .label_char
  90.     cmp.b    #'0',d1
  91.     blo.s    .label_bad
  92.     cmp.b    #'9',d1
  93.     bls.s    .label_char
  94. .test_alfa:
  95.     st    d2
  96.     cmp.b    #'A',d1
  97.     blo.s    .label_bad
  98.     cmp.b    #'Z',d1
  99.     bls.s    .label_char
  100.     cmp.b    #'a',d1
  101.     blo.s    .label_bad
  102.     cmp.b    #'z',d1
  103.     bls.s    .label_char
  104. .label_bad:
  105.     suba.l    a0,a0        ;return NULL on error
  106. .exit:
  107.     movem.l    (sp)+,d1-d2/a1
  108.     rts
  109. .ENDM    code_is_domname
  110. ;
  111. ;-------------------------------------------------------------------------------------)
  112. ;char    *is_dip(char *string)        /* flags -> dotted ip */
  113. ;
  114. .MACRO    is_dip.mode    string_p
  115.     PUREC_func.mode    is_dip,1,3,string_p
  116. .ENDM    is_dip
  117. ;
  118. .MACRO    code_is_dip
  119.     movem.l    d1/a1,-(sp)
  120.     move.l    a0,d0
  121.     beq.s    .exit
  122.     skip_space    (a0)
  123.     move.l    a0,a1
  124.     moveq    #3,d1
  125. .loop:
  126.     move.b    (a0)+,d0
  127.     cmp.b    #'.',d0
  128.     bne.s    .try_digits
  129.     dbra    d1,.loop
  130.     bra.s    .make_null
  131. ;
  132. .try_digits:
  133.     cmp.b    #'0',d0
  134.     blo.s    .test_dip
  135.     cmp.b    #'9',d0
  136.     bls.s    .loop
  137. .test_dip:
  138.     tst    d1
  139.     bne.s    .make_null
  140.     move.l    a1,a0
  141. .exit:
  142.     movem.l    (sp)+,d1/a1
  143.     rts
  144. ;
  145. .make_null:
  146.     suba.l    a0,a0
  147.     movem.l    (sp)+,d1/a1
  148.     rts
  149. .ENDM    code_is_dip
  150. ;
  151. ;-------------------------------------------------------------------------------------)
  152. ;char    *is_unblank(char *string)    /* flags -> unblank string */
  153. ;
  154. .MACRO    is_unblank.mode    string_p
  155.     PUREC_func.mode    is_unblank,1,3,string_p
  156. .ENDM    is_unblank
  157. ;
  158. .MACRO    code_is_unblank
  159.     move.l    a0,d0
  160.     beq.s    .exit
  161.     skip_space    (a0)
  162.     tst.b    (a0)
  163.     bne.s    .exit
  164.     suba.l    a0,a0
  165. .exit:
  166.     rts
  167. .ENDM    code_is_unblank
  168. ;
  169. ;-------------------------------------------------------------------------------------)
  170. ;char    *next_dip(char *string)        /* passes comma-separated arguments */
  171. ;
  172. .MACRO    next_dip.mode    string_p
  173.     PUREC_func.mode    next_dip,1,3,string_p
  174. .ENDM    next_dip
  175. ;
  176. .MACRO    code_next_dip
  177. .loop:
  178.     move.l    a0,d0
  179.     beq.s    .exit
  180.     move.b    (a0)+,d0
  181.     beq.s    .back_a0        ;refuse to pass terminator
  182.     cmp.b    #';',d0
  183.     beq.s    .pass_tail    ;pass entire comment
  184.     cmp.b    #',',d0
  185.     bne.s    .loop    ;accept comma as separator
  186.     skip_space    (a0)
  187.     rts
  188. ;
  189. .pass_tail:
  190.     tst.b    (a0)+
  191.     bne.s    .pass_tail    ;pass all non-terminators
  192. .back_a0:
  193.     subq    #1,a0        ;back a0 to terminator
  194. .exit:
  195.     rts
  196. .ENDM    code_next_dip
  197. ;
  198. ;-------------------------------------------------------------------------------------)
  199. ;char    *skip_space(char *string)    /* skips leading spaces & tabs */
  200. ;
  201. .MACRO    skip_space.mode    string_p
  202.     PUREC_func.mode    skip_space,1,3,string_p
  203. .ENDM    skip_space
  204. ;
  205. .MACRO    code_skip_space
  206. .loop:
  207.     move.l    a0,d0
  208.     beq.s    .exit
  209.     move.b    (a0)+,d0
  210.     cmp.b    #' ',d0        ;space ?
  211.     beq.s    .loop        ;pass leading spaces
  212.     cmp.b    #$09,d0        ;HT ?
  213.     beq.s    .loop        ;pass leading tabs
  214.     subq    #1,a0
  215. .exit:
  216.     rts
  217. .ENDM    code_skip_space
  218. ;
  219. ;-------------------------------------------------------------------------------------)
  220. ;uint32    diptobip(char *s_p)
  221. ;
  222. .MACRO    diptobip.mode    string_p
  223.     PUREC_func.mode    diptobip,1,3,string_p
  224. .ENDM    diptobip
  225. ;
  226. .MACRO    code_diptobip
  227.     movem.l    d1-d2,-(sp)
  228.     skip_space    (a0)
  229.     moveq    #-1,d0
  230.     cmp.b    #'0',(a0)
  231.     blo.s    .exit
  232.     cmp.b    #'9',(a0)
  233.     bhi.s    .exit
  234.     clr.l    d0
  235.     moveq    #4-1,d2
  236. .loop_1:
  237.     clr    d1
  238. .loop_2:
  239.     cmp.b    #'0',(a0)
  240.     blo.s    .exit_loop_2
  241.     cmp.b    #'9',(a0)
  242.     bhi.s    .exit_loop_2
  243.     mulu    #10,d1
  244.     add.b    (a0)+,d1
  245.     sub    #'0',d1
  246.     and    #$FF,d1
  247.     bra.s    .loop_2
  248. ;
  249. .exit_loop_2:
  250.     lsl.l    #8,d0
  251.     or.l    d1,d0
  252.     cmp.b    #'.',(a0)+
  253.     beq.s    .next_loop_1
  254.     subq    #1,a0
  255. .next_loop_1:
  256.     dbra    d2,.loop_1
  257. .exit:
  258.     movem.l    (sp)+,d1-d2
  259.     rts
  260. .ENDM    code_diptobip
  261. ;
  262. ;-------------------------------------------------------------------------------------)
  263. ;char    *biptodip(uint32 ip_n, char *s_p)
  264. ;
  265. .MACRO    biptodip.mode    ip_n,string_p
  266.     PUREC_func.mode    biptodip,2,$E,ip_n,string_p
  267. .ENDM    biptodip
  268. ;
  269. .MACRO    code_biptodip
  270.     movem.l    d1-d2,-(sp)
  271.     moveq    #4-1,d2
  272. .loop:
  273.     move.l    a0,a1            ;a1 = a0 = start of next number
  274.     rol.l    #8,d0
  275.     clr.l    d1
  276.     move.b    d0,d1
  277.     divu    #100,d1
  278.     beq.s    .hundreds_done
  279.     add.b    #'0',d1
  280.     move.b    d1,(a0)+
  281.     clr.w    d1
  282. .hundreds_done:
  283.     swap    d1
  284.     divu    #10,d1
  285.     bne.s    .use_tens_digit
  286.     cmpa.l    a0,a1            ;no hundreds digit ?
  287.     beq.s    .tens_done
  288. .use_tens_digit:
  289.     add.b    #'0',d1
  290.     move.b    d1,(a0)+
  291.     clr.w    d1
  292. .tens_done:
  293.     swap    d1
  294.     add.b    #'0',d1
  295.     move.b    d1,(a0)+
  296.     move.b    #'.',(a0)+
  297.     dbra    d2,.loop
  298.     clr.b    -(a0)
  299.     move.l    a0,d0
  300.     movem.l    (sp)+,d1-d2
  301.     rts
  302. .ENDM    code_biptodip
  303. ;
  304. ;-------------------------------------------------------------------------------------)
  305. ;char    *biptodrip(uint32 ip_n, char *s_p)
  306. ;
  307. .MACRO    biptodrip.mode    ip_n,string_p
  308.     PUREC_func.mode    biptodrip,2,$E,ip_n,string_p
  309. .ENDM    biptodrip
  310. ;
  311. .MACRO    code_biptodrip
  312.     movem.l    d1-d2,-(sp)
  313.     moveq    #4-1,d2
  314. .loop:
  315.     move.l    a0,a1            ;a1 = a0 = start of next number
  316.     clr.l    d1
  317.     move.b    d0,d1
  318.     divu    #100,d1
  319.     beq.s    .hundreds_done
  320.     add.b    #'0',d1
  321.     move.b    d1,(a0)+
  322.     clr.w    d1
  323. .hundreds_done:
  324.     swap    d1
  325.     divu    #10,d1
  326.     bne.s    .use_tens_digit
  327.     cmpa.l    a0,a1            ;no hundreds digit ?
  328.     beq.s    .tens_done
  329. .use_tens_digit:
  330.     add.b    #'0',d1
  331.     move.b    d1,(a0)+
  332.     clr.w    d1
  333. .tens_done:
  334.     swap    d1
  335.     add.b    #'0',d1
  336.     move.b    d1,(a0)+
  337.     move.b    #'.',(a0)+
  338.     ror.l    #8,d0
  339.     dbra    d2,.loop
  340.     clr.b    -(a0)
  341.     move.l    a0,d0
  342.     movem.l    (sp)+,d1-d2
  343.     rts
  344. .ENDM    code_biptodrip
  345. ;
  346. ;-------------------------------------------------------------------------------------)
  347. ;char *pass_RRname(char *data_p, char *pos_p, char *dest_p)
  348. ;
  349. .MACRO    pass_RRname.mode    data_p,pos_p,dest_p
  350.     PUREC_func.mode    pass_RRname,3,$3F,data_p,pos_p,dest_p
  351. .ENDM    pass_RRname
  352. ;
  353. .MACRO    code_pass_RRname
  354.     movem.l    d1-d2/a1-a2,-(sp)
  355.     move.l    a2,-(sp)
  356.     move.l    8(sp),a2
  357.     clr.l    d2
  358. .loop_2:
  359.     clr    d0
  360.     move.b    (a1)+,d0
  361.     beq.s    .exit
  362.     bpl.s    .no_compr
  363.     and    #$3F,d0        ;d0 == compression mark ?
  364.     lsl    #8,d0
  365.     move.b    (a1)+,d0    ;d0 = compressed label
  366.     tst.l    d2        ;done some expansion ?
  367.     bne.s    .keep_d2
  368.     move.l    a1,d2        ;d2 = a1 -> type beyond current name name
  369. .keep_d2:
  370.     lea    -12(a0,d0),a1    ;a1 -> expansion label
  371.     bra.s    .loop_2        ;go expand label
  372. ;
  373. .no_compr:
  374.     move.l    a2,d1        ;dest_p == NULL ?
  375.     beq.s    .skip_1
  376.     subq    #1,d0
  377. .loop_1:
  378.     move.b    (a1)+,(a2)+    ;store string
  379.     dbra    d0,.loop_1
  380.     move.b    #'.',(a2)+    ;store '.'
  381.     bra.s    .loop_2
  382. ;
  383. .skip_1:
  384.     add    d0,a1        ;pass string
  385.     bra.s    .loop_2
  386. ;
  387. .exit:
  388.     move.l    a2,d1        ;dest_p == NULL ?
  389.     beq.s    .skip_2
  390.     cmp.b    #'.',-(a2)
  391.     bne.s    .skip_2
  392.     clr.b    (a2)
  393. .skip_2:
  394.     tst.l    d2        ;done some expansion ?
  395.     bne.s    .return_d2
  396.     move.l    a1,d2        ;d2 = a1 -> type beyond current name
  397. .return_d2:
  398.     movem.l    (sp)+,a2
  399.     move.l    d2,a0
  400.     movem.l    (sp)+,d1-d2/a1-a2
  401.     rts
  402. .ENDM    code_pass_RRname
  403. ;
  404. ;----------------------------------------------------------------------------
  405. ; End of file:    DOMAIN.SH
  406. ;----------------------------------------------------------------------------
  407.